import http from './http'
// const baseUrl = 'http://172.23.152.88:8082';
// const baseUrl = 'http://60.205.178.38:80'
const baseUrl = 'http://localhost:8082'
// 获取管理员信息
export const getAdminInfo = () => {
  if (process.client) {
    return http.requestGet('/portal/user/adminUserInfo')
  } else {
    return http.requestGet(baseUrl + '/portal/user/adminUserInfo')
  }
}
// 获取验证码
export const getVerify = (captchaKey) => {
  localStorage.setItem('captchaKey', captchaKey)
  if (process.client) {
    return http.requestGet('/user/captcha?captchaKey=' + captchaKey)
  } else {
    return http.requestGet(baseUrl + '/user/captcha?captchaKey=' + captchaKey)
  }
}
// 检查邮箱是否重复
export const checkUserEmail = (emailAddress) => {
  if (process.client) {
    return http.requestGet('/user/email?email=' + emailAddress)
  } else {
    return http.requestGet(baseUrl + '/user/email?email=' + emailAddress)
  }
}
// 获取邮箱验证码
export const getEmailVerify = (emailAddress) => {
  if (process.client) {
    return http.requestGet('/user/verify_code?emailAddress=' + emailAddress)
  } else {
    return http.requestGet(baseUrl + '/user/verify_code?emailAddress=' + emailAddress)
  }
}
// 校验用户
export const checkToken = () => {
  if (process.client) {
    return http.requestGet('/user/check-token')
  } else {
    return http.requestGet(baseUrl + '/user/check-token')
  }
}
// 登录
export const doLogin = (captcha, captcha_key, sobUser) => {
  if (process.client) {
    return http.requestPost('/user/login/' + captcha + '/' + captcha_key, sobUser)
  } else {
    return http.requestPost(baseUrl + '/user/login/' + captcha + '/' + captcha_key, sobUser)
  }
}
// 注册
export const register = (email_code, user) => {
  if (process.client) {
    return http.requestPost('/user/register?email_code=' + email_code, user)
  } else {
    return http.requestPost(baseUrl + '/user/register?email_code=' + email_code, user)
  }
}
// 退出登录
export const doLogout = () => {
  if (process.client) {
    return http.requestGet('/user/logout')
  } else {
    return http.requestGet(baseUrl + '/user/logout')
  }
}
/** **文章 */

// 获取各个分类的文章总数
export const getCategoryArticleCount = () => {
  if (process.client) {
    return http.requestGet('/portal/article/category/count')
  } else {
    return http.requestGet(baseUrl + '/portal/article/category/count')
  }
}

// 搜索文章
export const getSearchArticleList = (categoryId, keyword, pageNo, pageSize, sort) => {
  if (process.client) {
    return http.requestGet('/portal/article/search?categoryId=' + categoryId + '&keyword=' + keyword + '&pageNo=' + pageNo + '&pageSize=' + pageSize + '&sort=' + sort)
  } else {
    return http.requestGet(baseUrl + '/portal/article/search?categoryId=' + categoryId + '&keyword=' + keyword + '&pageNo=' + pageNo + '&pageSize=' + pageSize + '&sort=' + sort)
  }
}
// 根据条件获取文章列表
export const getComparisonOperation = (pageNo, pageSize, label, categoryId, timeline) => {
  if (process.client) {
    return http.requestGet('/portal/article/articlelist?pageNo=' + pageNo + '&pageSize=' + pageSize + '&label=' + label + '&categoryId=' + categoryId + '&timeline=' + timeline)
  } else {
    return http.requestGet(baseUrl + '/portal/article/articlelist?pageNo=' + pageNo + '&pageSize=' + pageSize + '&label=' + label + '&categoryId=' + categoryId + '&timeline=' + timeline)
  }
}
// 获取推荐文章
// TODO
export const getRecommendArticle = (articleId, size) => {
  if (process.client) {
    return http.requestGet('/portal/article/recommend/' + articleId + '/' + size)
  } else {
    return http.requestGet(baseUrl + '/portal/article/recommend/' + articleId + '/' + size)
  }
}
// 根据id获取文章详情
export const getArticleById = (articleId) => {
  if (process.client) {
    return http.requestGet('/portal/article/' + articleId)
  } else {
    return http.requestGet(baseUrl + '/portal/article/' + articleId)
  }
}
// 获取标签
export const getArticleLabel = (size) => {
  if (process.client) {
    // 客户端
    return http.requestGet('/portal/article/label?size=' + size)
  } else {
    return http.requestGet(baseUrl + '/portal/article/label?size=' + size)
  }
}
// 获取文章列表
export const getArticleList = (pageNo, pageSize) => {
  if (process.client) {
    return http.requestGet('/portal/article/list?pageNo=' + pageNo + '&pageSize=' + pageSize)
  } else {
    return http.requestGet(baseUrl + '/portal/article/list?pageNo=' + pageNo + '&pageSize=' + pageSize)
  }
}
/**
 * 删除评论
 * @param {*} commentId 评论id
 * @returns
 */
// 删除文章评论
export const deleteComment = (commentId) => {
  if (process.client) {
    return http.requestDelete('/portal/comments/' + commentId)
  } else {
    return http.requestDelete(baseUrl + '/portal/comments/' + commentId)
  }
}
// 获取文章评论
export const getArticleComment = (articleId) => {
  if (process.client) {
    return http.requestGet('/portal/comments/list/' + articleId)
  } else {
    return http.requestGet(baseUrl + '/portal/comments/list/' + articleId)
  }
}
// 添加文章评论
export const addArticleComment = (comment) => {
  if (process.client) {
    return http.requestPost('/portal/comments', comment)
  } else {
    return http.requestPost(baseUrl + '/portal/comments', comment)
  }
}
// 获取置顶文章
export const getArticleTop = () => {
  if (process.client) {
    return http.requestGet('/portal/article/top')
  } else {
    return http.requestGet(baseUrl + '/portal/article/top')
  }
}
// 获取文章数量
export const getArticleCount = () => {
  if (process.client) {
    return http.requestGet('/portal/article/count')
  } else {
    return http.requestGet(baseUrl + '/portal/article/count')
  }
}
// 最热文章
export const getHottestArticle = () => {
  if (process.client) {
    return http.requestGet('/portal/article/hottest-articles')
  } else {
    return http.requestGet(baseUrl + '/portal/article/hottest-articles')
  }
}
// 最新文章
export const getLasterArticle = () => {
  if (process.client) {
    return http.requestGet('/portal/article/laster-articles')
  } else {
    return http.requestGet(baseUrl + '/portal/article/laster-articles')
  }
}
/**  获取网站信息 */
// 获取用户数量
export const getUserCount = () => {
  if (process.client) {
    return http.requestGet('/portal/user/count')
  } else {
    return http.requestGet(baseUrl + '/portal/user/count')
  }
}
// 获取评论数量
export const getCommentCount = () => {
  if (process.client) {
    return http.requestGet('/portal/comments/count')
  } else {
    return http.requestGet(baseUrl + '/portal/comments/count')
  }
}
// 获取网站浏览量
export const getViewCount = () => {
  if (process.client) {
    return http.requestGet('/portal/web_size_info/view_count')
  } else {
    return http.requestGet(baseUrl + '/portal/web_size_info/view_count')
  }
}

// 更新网站浏览量
export const updateViewCount = () => {
  if (process.client) {
    return http.requestPut('/portal/web_size_info/view_count')
  } else {
    return http.requestPut(baseUrl + '/portal/web_size_info/view_count')
  }
}
// 获取轮播图
export const getLoopList = () => {
  if (process.client) {
    return http.requestGet('/portal/web_size_info/loop')
  } else {
    return http.requestGet(baseUrl + '/portal/web_size_info/loop')
  }
}
export const getFriengLinkList = () => {
  if (process.client) {
    return http.requestGet('/portal/web_size_info/friend_link')
  } else {
    return http.requestGet(baseUrl + '/portal/web_size_info/friend_link')
  }
}
